//
//  GameCell.swift
//  swiftDemo
//
//  Created by Gerry on 2022/1/7.
//

import UIKit

class GameCell: UICollectionViewCell {
    
    var model : GameModel?
    
    private lazy var iconImageView : UIImageView = {
        let imgView = UIImageView()
//        imgView.backgroundColor = UIColor.orange
        imgView.layer.cornerRadius = 5
        imgView.layer.masksToBounds = true
        return imgView
    } ()
    
    private lazy var titleLab : UILabel = {
       let lab = UILabel()
        lab.font = UIFont.systemFont(ofSize: 12)
        lab.textColor = UIColor.init(hexString: "#333333")
        lab.textAlignment = .center
        
//        lab.backgroundColor = UIColor.yellow
        return lab
    }()
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.addSubview(iconImageView)
        contentView.addSubview(titleLab)
        
        iconImageView.snp.makeConstraints { make in
            make.top.equalTo(10)
            make.centerX.equalTo(contentView)
            make.size.equalTo(CGSize.init(width: 50, height: 50))
        }
        
        titleLab.snp.makeConstraints { make in
            make.top.equalTo(iconImageView.snp.bottom).offset(6)
            make.centerX.equalTo(contentView)
            make.left.equalTo(0)
            make.right.equalTo(0)
        }
    }
    
    func setGameModel(model : GameModel) {
        iconImageView.sd_setImage(with: URL.init(string: model.icon_url), completed: nil)
        titleLab.text = model.tag_name
    }
}
